{% extends "public/layout.html" %}



{% block sidebar %}
    {% include "public/cmdb_left.html" %}
{% endblock %}


{% block custom_css %}
    <style>
        .btn_mod{font-size: 14px;padding:2px 6px;}
        .server_idc_list_button{float:right; margin-right: 10px;margin-bottom: 10px;}
    </style>
{% endblock %}

{% block body %}
<div class="right_content">
    <a class="btn btn-default server_idc_list_button" href="/resources/idc/add/" style="float:right;" role="button">添加IDC</a>
    <div id="tab_box" >
        <table class="table table-striped table-bordered" cellspacing="0" style="width:100%;">
            <tr>
                <th>#</th>
                <th>IDC字母简称</th>
                <th>idc名称</th>
                <th>IDC详细地址</th>
                <th>客服电话</th>
                <th>邮件地址</th>
                <th>IDC接口人</th>
                <th>接口人电话</th>
                <th>实际机柜数</th>
                <th>合同机柜数</th>
                <th>操作</th>
            </tr>
            {% for idc in idcs %}
                <tr>

                    <td>{{ loop.index }}</td>
                    <td>{{ idc.name }}</td>
                    <td>{{ idc.idc_name }}</td>
                    <td>{{ idc.address }}</td>
                    <td>{{ idc.phone }}</td>
                    <td>{{ idc.email }}</td>
                    <td>{{ idc.user_interface }}</td>
                    <td>{{ idc.user_phone }}</td>
                    <td>{{ idc.rel_cabinet_num }}</td>
                    <td>{{ idc.pact_cabinet_num }}</td>
                    <td>
                        <a href="/resources/idc/modify/{{ idc.id }}" class="btn btn-primary btn_mod">修改</a>
                        <a href="#" idc_id="{{ idc.id }}" class="btn btn-danger btn_mod btn_delete">删除</a>
                    </td>
                </tr>
            {% endfor %}
        </table>
    </div>
</div>
{% endblock %}
{% block js %}
    <script>
        $(".btn_delete").click(function(){
            var obj = $(this)
            var id = obj.attr("idc_id");
            // 在浏览器开发者工具中的控制台打印 信息 方便调试
            console.log(id); 
            swal({title: "确定删除吗?",
                text: "即将删除这条IDC信息",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "删除",
                cancelButtonText: "取消",
                closeOnConfirm: false
            }, function(){
                // url = "/resources/idc/delete/"
                $.post("/resources/idc/delete/", {"id":id}, function (data) {
                    console.log(data); 
                    if (data == "1"){
                        console.log(obj.parents('tr')); 
                        obj.parents('tr').remove();
                        swal("删除成功!", "", "success");
                    }else {
                        swal("删除成功!", "", "error");
                    }
                });

            });
            return false
        });


    </script>
{% endblock %}

